// packageJ/consensus_activity/integrate/integrate.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    total_page: 1,
    list: [],
    text:"",

    count: 0,
    type: null, //1-元积分、2-元积分提现配额、3-收益积分、4-质积分、5-加权分红额度、6-加权分红
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      type: Number(options.num)
    })
    if (options.count) {
      this.setData({
        count: options.count
      })
    }
    if (this.data.type == 5) {
      wx.setNavigationBarTitle({
        title: '加权分红额度',
      })
      this.get_dividend_log();
    } else if (this.data.type == 6) { //加权分红
      this.get_dividend_log();
      wx.setNavigationBarTitle({
        title: '加权分红',
      })
    } else {
      this.getData();
    }
  },
  get_dividend_log(page = 1) {
    let urlStr = "plugin.wise-yuan-trade.frontend.my.add-weighted-dividend-log";
    if (this.data.type == 5) {
      urlStr = 'plugin.wise-yuan-trade.frontend.my.add-weighted-dividend-limit-log';
    }
    app._getNetWork({
      url: app.getNetAddresss(urlStr),
      data: {
        page
      },
      success: resdata => {
        let {
          result,
          msg,
          data
        } = resdata.data;
        if (result) {
          if (page == 1) {
            this.setData({
              list: data.data
            })
          } else {
            let list = this.data.list.concat(data.data);
            this.setData({
              list
            })
          }
          this.data.page = data.current_page;
          this.data.total_page = data.last_page;
          if(this.data.type==6){
            let count = data.total_reward_value;
            this.setData({count})
          }
        } else {
          app.tips(msg);
        }
      }
    })
  },
  getData() {
    let _url = "plugin.wise-yuan-trade.frontend.my.custom-name";
    if(this.data.type == 4){
      _url = "plugin.wise-yuan-trade.frontend.quality.index";
    }
    app._getNetWork({
      url: app.getNetAddresss(_url),
      success: resdata => {
        let {
          result,
          data,
          msg
        } = resdata.data;
        if (result) {
          let type = this.data.type;
          let text = "";
          if (type == 1) {
            text = data.yuan_name;
          } else if (type == 2) {
            text = data.yuan_withdraw_limit_name;
          } else if (type == 3) {
            text = data.income_name;
          } else if (type == 4) {
            text = data.quality_name;
            this.setData({count:data.quality})
          }
          wx.setNavigationBarTitle({
            title: text,
          })
          this.setData({text})
          if(this.data.type == 4){
            this.get_point_record();
          }else{
            this.get_detail();
          }
        } else {
          app.tips(msg);
        }
      }
    })

  },
  get_detail(){
    let urlStr = "";
    if (this.data.type == 1 || this.data.type == 2) {
      urlStr = 'plugin.wise-yuan-trade.frontend.yuan-point.index';
    } else if (this.data.type == 3) {
      urlStr = 'plugin.wise-yuan-trade.frontend.income-point.index';
    } else if (this.data.type == 4) {//质积分

    }
    app._getNetWork({
      url:app.getNetAddresss(urlStr),
      success:resdata=>{
        let {result,msg,data} = resdata.data;
        if(result){
          if (this.data.type == 1 || this.data.type == 2) {
            if (this.data.type == 1) {
              this.setData({count:data.usable_yuan})
            } else {
              this.setData({count:data.yuan_withdraw_quota})
            }
          }else if(this.data.type == 3){
            this.setData({count:data.income})
          }
          this.get_point_record();
        }else{
          app.tips(msg);
        }
      }
    })
  },
  get_point_record(page=1){
    let urlStr = 'plugin.wise-yuan-trade.frontend.yuan-point.record';
    if (this.data.type == 2) {
      urlStr = "plugin.wise-yuan-trade.frontend.yuan-point.quota-record";
    } else if (this.data.type == 3) {
      urlStr = 'plugin.wise-yuan-trade.frontend.income-point.record';
    } else if (this.data.type == 4) {
      urlStr = 'plugin.wise-yuan-trade.frontend.quality.record';
    }
    app._getNetWork({
      url:app.getNetAddresss(urlStr),
      data:{page},
      success:resdata=>{
        let {result,msg,data} = resdata.data;
        if(result){
          if (page == 1) {
            this.setData({
              list: data.data
            })
          } else {
            let list = this.data.list.concat(data.data);
            this.setData({
              list
            })
          }
          this.data.page = data.current_page;
          this.data.total_page = data.last_page;
        }else{
          app.tips(msg);
        }
      }
    })

  },
  goto() {
    // :to="fun.getUrl('consensus_activity_withdraw',{num:type})"
    wx.navigateTo({
      url: '/packageJ/consensus_activity/withdraw/withdraw?num=' + this.data.type,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.page >= this.data.total_page) {
      return;
    }
    let page = this.data.page + 1;
    if(this.data.type==6){
      this.get_dividend_log(page);
    }else{
      this.get_point_record(page);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})